module hybrid_coord_test_mod

  use flogger
  use const_mod
  use process_mod
  use mesh_mod

  implicit none

  private

  public hybrid_coord_test_l15
  public hybrid_coord_test_l26
  public hybrid_coord_test_l30
  public hybrid_coord_test_l95
  public hybrid_coord_wrf_l16
  public hybrid_coord_wrf_l26
  public hybrid_coord_wrf_l32
  public hybrid_coord_wrf_l60
  public hybrid_coord_wrf_l64
  public hybrid_coord_schar_l40
  public hybrid_coord_dcmip21_l60
  public hybrid_coord_dcmip31_l10
  public hybrid_coord_waccm_l70

contains

  subroutine hybrid_coord_test_l15(p0, ptop, hyai, hybi)

    real(r8), intent(out) :: p0
    real(r8), intent(out) :: ptop
    real(r8), intent(out) :: hyai(16)
    real(r8), intent(out) :: hybi(16)

    if (global_mesh%num_full_lev /= 15 .and. is_root_proc()) then
      call log_error('num_lev should be 15 in namelist!')
    end if

    hyai = [0.20540233  , & !  1
            0.19853043  , & !  2
            0.19095544  , & !  3
            0.18262359  , & !  4
            0.17347834  , & !  5
            0.16346029  , & !  6
            0.15250707  , & !  7
            0.14055334  , & !  8
            0.12753061  , & !  9
            0.11336724  , & !  10
            0.09798832  , & !  11
            0.08131559  , & !  12
            0.06326738  , & !  13
            0.04375850  , & !  14
            0.02270019  , & !  15
            0.00000000]     !  16
    hybi = [0.00000     , & !  1
            0.03345579  , & !  2
            0.07033459  , & !  3
            0.11089815  , & !  4
            0.15542174  , & !  5
            0.20419459  , & !  6
            0.25752023  , & !  7
            0.31571693  , & !  8
            0.37911800  , & !  9
            0.44807228  , & !  10
            0.52294448  , & !  11
            0.60411556  , & !  12
            0.69198316  , & !  13
            0.78696201  , & !  14
            0.88948427  , & !  15
            1.00000000]     !  16

    p0 = 1d5 ! Pa
    ptop = p0 * hyai(1)

  end subroutine hybrid_coord_test_l15

  subroutine hybrid_coord_test_l26(p0, ptop, hyai, hybi)

    real(r8), intent(out) :: p0
    real(r8), intent(out) :: ptop
    real(r8), intent(out) :: hyai(27)
    real(r8), intent(out) :: hybi(27)

    if (global_mesh%num_full_lev /= 26 .and. is_root_proc()) then
      call log_error('num_lev should be 26 in namelist!')
    end if

    hyai = [0.002194067  , & !  1
            0.004895209  , & !  2
            0.009882418  , & !  3
            0.01805201   , & !  4
            0.02983724   , & !  5
            0.04462334   , & !  6
            0.06160587   , & !  7
            0.07851243   , & !  8
            0.07731271   , & !  9
            0.07590131   , & ! 10
            0.07424086   , & ! 11
            0.07228744   , & ! 12
            0.06998933   , & ! 13
            0.06728574   , & ! 14
            0.06410509   , & ! 15
            0.06036322   , & ! 16
            0.05596111   , & ! 17
            0.05078225   , & ! 18
            0.04468960   , & ! 19
            0.03752191   , & ! 20
            0.02908949   , & ! 21
            0.02084739   , & ! 22
            0.01334443   , & ! 23
            0.00708499   , & ! 24
            0.00252136   , & ! 25
            0.00000000   , & ! 26
            0.00000000]      ! 27

    hybi = [0.000000     , & !  1
            0.000000     , & !  2
            0.000000     , & !  3
            0.000000     , & !  4
            0.000000     , & !  5
            0.000000     , & !  6
            0.000000     , & !  7
            0.000000     , & !  8
            0.01505309   , & !  9
            0.03276228   , & ! 10
            0.05359622   , & ! 11
            0.07810627   , & ! 12
            0.1069411    , & ! 13
            0.1408637    , & ! 14
            0.1807720    , & ! 15
            0.2277220    , & ! 16
            0.2829562    , & ! 17
            0.3479364    , & ! 18
            0.4243822    , & ! 19
            0.5143168    , & ! 20
            0.6201202    , & ! 21
            0.7235355    , & ! 22
            0.8176768    , & ! 23
            0.8962153    , & ! 24
            0.9534761    , & ! 25
            0.9851122    , & ! 26
            1.0000000]       ! 27

    p0 = 1d5 ! Pa
    ptop = p0 * hyai(1)

  end subroutine hybrid_coord_test_l26

  subroutine hybrid_coord_test_l30(p0, ptop, hyai, hybi)

    real(r8), intent(out) :: p0
    real(r8), intent(out) :: ptop
    real(r8), intent(out) :: hyai(31)
    real(r8), intent(out) :: hybi(31)

    if (global_mesh%num_full_lev /= 30 .and. is_root_proc()) then
      call log_error('num_lev should be 30 in namelist!')
    end if

    hyai = [0.20540233  , & !  1
            0.20205101  , & !  2
            0.19853043  , & !  3
            0.19483412  , & !  4
            0.19095544  , & !  5
            0.18688759  , & !  6
            0.18262359  , & !  7
            0.17815629  , & !  8
            0.17347834  , & !  9
            0.16858224  , & !  10
            0.16346029  , & !  11
            0.15810459  , & !  12
            0.15250707  , & !  13
            0.14665948  , & !  14
            0.14055334  , & !  15
            0.13418     , & !  16
            0.12753061  , & !  17
            0.12059611  , & !  18
            0.11336724  , & !  19
            0.10583453  , & !  20
            0.09798832  , & !  21
            0.0898187   , & !  22
            0.08131559  , & !  23
            0.07246866  , & !  24
            0.06326738  , & !  25
            0.05370098  , & !  26
            0.0437585   , & !  27
            0.03342871  , & !  28
            0.02270019  , & !  29
            0.01156125  , & !  30
            0.00000000]     !  31

    hybi = [0.00000     , & !  1
            0.01631585  , & !  2
            0.03345579  , & !  3
            0.05145127  , & !  4
            0.07033459  , & !  5
            0.09013889  , & !  6
            0.11089815  , & !  7
            0.13264719  , & !  8
            0.15542174  , & !  9
            0.17925837  , & !  10
            0.20419459  , & !  11
            0.23026877  , & !  12
            0.25752023  , & !  13
            0.28598922  , & !  14
            0.31571693  , & !  15
            0.34674548  , & !  16
            0.37911800  , & !  17
            0.41287857  , & !  18
            0.44807228  , & !  19
            0.48474521  , & !  20
            0.52294448  , & !  21
            0.56271820  , & !  22
            0.60411556  , & !  23
            0.64718678  , & !  24
            0.69198316  , & !  25
            0.73855571  , & !  26
            0.78696201  , & !  27
            0.83725251  , & !  28
            0.88948427  , & !  29
            0.94371412  , & !  30
            1.00000000]     !  31

    p0 = 1d5 ! Pa
    ptop = p0 * hyai(1)

  end subroutine hybrid_coord_test_l30

  subroutine hybrid_coord_test_l95(p0, ptop, hyai, hybi)

    real(r8), intent(out) :: p0
    real(r8), intent(out) :: ptop
    real(r8), intent(out) :: hyai(96)
    real(r8), intent(out) :: hybi(96)

    if (global_mesh%num_full_lev /= 95 .and. is_root_proc()) then
      call log_error('num_lev should be 95 in namelist!')
    end if

    hyai = [          &
      5.0000000e-02,  &
      6.0000000e-02,  &
      7.0000000e-02,  &
      8.0000000e-02,  &
      9.0000000e-02,  &
      1.0000000e-01,  &
      1.1000000e-01,  &
      1.2000000e-01,  &
      1.3000000e-01,  &
      1.4000000e-01,  &
      1.5000000e-01,  &
      1.6000000e-01,  &
      1.7000000e-01,  &
      1.8000000e-01,  &
      1.9000000e-01,  &
      2.0000000e-01,  &
      2.1000000e-01,  &
      2.2000000e-01,  &
      2.3000000e-01,  &
      2.4000000e-01,  &
      2.5000000e-01,  &
      2.6000000e-01,  &
      2.7000000e-01,  &
      2.8000000e-01,  &
      2.9000000e-01,  &
      3.0000000e-01,  &
      3.0953440e-01,  &
      3.1815277e-01,  &
      3.2587784e-01,  &
      3.3273236e-01,  &
      3.3873907e-01,  &
      3.4392070e-01,  &
      3.4830000e-01,  &
      3.5189971e-01,  &
      3.5474257e-01,  &
      3.5685131e-01,  &
      3.5824869e-01,  &
      3.5895743e-01,  &
      3.5900029e-01,  &
      3.5840000e-01,  &
      3.5717930e-01,  &
      3.5536093e-01,  &
      3.5296764e-01,  &
      3.5002216e-01,  &
      3.4654723e-01,  &
      3.4256560e-01,  &
      3.3810000e-01,  &
      3.3317318e-01,  &
      3.2780787e-01,  &
      3.2202682e-01,  &
      3.1585277e-01,  &
      3.0930845e-01,  &
      3.0241662e-01,  &
      2.9520000e-01,  &
      2.8768134e-01,  &
      2.7988338e-01,  &
      2.7182886e-01,  &
      2.6354052e-01,  &
      2.5504111e-01,  &
      2.4635335e-01,  &
      2.3750000e-01,  &
      2.2850379e-01,  &
      2.1938746e-01,  &
      2.1017376e-01,  &
      2.0088542e-01,  &
      1.9154519e-01,  &
      1.8217580e-01,  &
      1.7280000e-01,  &
      1.6344052e-01,  &
      1.5412012e-01,  &
      1.4486152e-01,  &
      1.3568746e-01,  &
      1.2662070e-01,  &
      1.1768397e-01,  &
      1.0890000e-01,  &
      1.0029155e-01,  &
      9.1881341e-02,  &
      8.3692128e-02,  &
      7.5746647e-02,  &
      6.8067638e-02,  &
      6.0677843e-02,  &
      5.3600000e-02,  &
      4.6856851e-02,  &
      4.0471137e-02,  &
      3.4465598e-02,  &
      2.8862974e-02,  &
      2.3686006e-02,  &
      1.8957434e-02,  &
      1.4700000e-02,  &
      1.0936443e-02,  &
      7.6895044e-03,  &
      4.9819242e-03,  &
      2.8364431e-03,  &
      1.2758017e-03,  &
      3.2274052e-04,  &
      0.0000000e+00   &
    ]

    hybi = [          &
      0.0000000e+00,  &
      0.0000000e+00,  &
      0.0000000e+00,  &
      0.0000000e+00,  &
      0.0000000e+00,  &
      0.0000000e+00,  &
      0.0000000e+00,  &
      0.0000000e+00,  &
      0.0000000e+00,  &
      0.0000000e+00,  &
      0.0000000e+00,  &
      0.0000000e+00,  &
      0.0000000e+00,  &
      0.0000000e+00,  &
      0.0000000e+00,  &
      0.0000000e+00,  &
      0.0000000e+00,  &
      0.0000000e+00,  &
      0.0000000e+00,  &
      0.0000000e+00,  &
      0.0000000e+00,  &
      0.0000000e+00,  &
      0.0000000e+00,  &
      0.0000000e+00,  &
      0.0000000e+00,  &
      2.0816682e-16,  &
      4.6559767e-04,  &
      1.8472303e-03,  &
      4.1221574e-03,  &
      7.2676385e-03,  &
      1.1260933e-02,  &
      1.6079300e-02,  &
      2.1700000e-02,  &
      2.8100292e-02,  &
      3.5257434e-02,  &
      4.3148688e-02,  &
      5.1751312e-02,  &
      6.1042566e-02,  &
      7.0999708e-02,  &
      8.1600000e-02,  &
      9.2820700e-02,  &
      1.0463907e-01,  &
      1.1703236e-01,  &
      1.2997784e-01,  &
      1.4345277e-01,  &
      1.5743440e-01,  &
      1.7190000e-01,  &
      1.8682682e-01,  &
      2.0219213e-01,  &
      2.1797318e-01,  &
      2.3414723e-01,  &
      2.5069155e-01,  &
      2.6758338e-01,  &
      2.8480000e-01,  &
      3.0231866e-01,  &
      3.2011662e-01,  &
      3.3817114e-01,  &
      3.5645948e-01,  &
      3.7495889e-01,  &
      3.9364665e-01,  &
      4.1250000e-01,  &
      4.3149621e-01,  &
      4.5061254e-01,  &
      4.6982624e-01,  &
      4.8911458e-01,  &
      5.0845481e-01,  &
      5.2782420e-01,  &
      5.4720000e-01,  &
      5.6655948e-01,  &
      5.8587988e-01,  &
      6.0513848e-01,  &
      6.2431254e-01,  &
      6.4337930e-01,  &
      6.6231603e-01,  &
      6.8110000e-01,  &
      6.9970845e-01,  &
      7.1811866e-01,  &
      7.3630787e-01,  &
      7.5425335e-01,  &
      7.7193236e-01,  &
      7.8932216e-01,  &
      8.0640000e-01,  &
      8.2314315e-01,  &
      8.3952886e-01,  &
      8.5553440e-01,  &
      8.7113703e-01,  &
      8.8631399e-01,  &
      9.0104257e-01,  &
      9.1530000e-01,  &
      9.2906356e-01,  &
      9.4231050e-01,  &
      9.5501808e-01,  &
      9.6716356e-01,  &
      9.7872420e-01,  &
      9.8967726e-01,  &
      1.0000000e+00   &
    ]

    p0 = 1d5 ! Pa
    ptop = p0 * hyai(1)

  end subroutine hybrid_coord_test_l95

  subroutine hybrid_coord_wrf_l16(p0, ptop, hyai, hybi)

    real(r8), intent(out) :: p0
    real(r8), intent(in ) :: ptop
    real(r8), intent(out) :: hyai(17)
    real(r8), intent(out) :: hybi(17)

    if (global_mesh%num_full_lev /= 16 .and. is_root_proc()) then
      call log_error('num_lev should be 16 in namelist!')
    end if

    hyai = [          &
      0.00000000e+00, &
      6.25000000e-02, &
      1.25000000e-01, &
      1.87500000e-01, &
      2.41699219e-01, &
      2.72331238e-01, &
      2.82287598e-01, &
      2.75001526e-01, &
      2.53906250e-01, &
      2.22434998e-01, &
      1.84020996e-01, &
      1.42097473e-01, &
      1.00097656e-01, &
      6.14547729e-02, &
      2.96020508e-02, &
      7.97271729e-03, &
      4.44089210e-16  &
    ]
    hybi = [          &
      0.00000000e+00, &
      0.00000000e+00, &
      0.00000000e+00, &
      0.00000000e+00, &
      8.30078125e-03, &
      4.01687622e-02, &
      9.27124023e-02, &
      1.62498474e-01, &
      2.46093750e-01, &
      3.40065002e-01, &
      4.40979004e-01, &
      5.45402527e-01, &
      6.49902344e-01, &
      7.51045227e-01, &
      8.45397949e-01, &
      9.29527283e-01, &
      1.00000000e+00  &
    ]

    p0 = 1d5       ! Pa

  end subroutine hybrid_coord_wrf_l16

  subroutine hybrid_coord_wrf_l26(p0, ptop, hyai, hybi)

    real(r8), intent(out) :: p0
    real(r8), intent(in ) :: ptop
    real(r8), intent(out) :: hyai(27)
    real(r8), intent(out) :: hybi(27)

    if (global_mesh%num_full_lev /= 26 .and. is_root_proc()) then
      call log_error('num_lev should be 26 in namelist!')
    end if

    hyai = [              &
      0.0000000000000000, & !  1
      0.0026949368990385, & !  2
      0.0076765830700214, & !  3
      0.0158441481359590, & !  4
      0.0276273570916710, & !  5
      0.0414422617493396, & !  6
      0.0562280278845174, & !  7
      0.0724791367109593, & !  8
      0.0893764691932271, & !  9
      0.1063516039069875, & ! 10
      0.1254699736141626, & ! 11
      0.1479612378540120, & ! 12
      0.1744206867899481, & ! 13
      0.2054467443488705, & ! 14
      0.2362331354387115, & ! 15
      0.2617244861517879, & ! 16
      0.2783056303113054, & ! 17
      0.2816242061994436, & ! 18
      0.2669746497908253, & ! 19
      0.2303286706439434, & ! 20
      0.1705682721867309, & ! 21
      0.1064887571082237, & ! 22
      0.0535041093004280, & ! 23
      0.0199854375869117, & ! 24
      0.0049141727575007, & ! 25
      0.0008271366689887, & ! 26
      0.0000000000000000  & ! 27
    ]
    hybi = [              &
      0.0000000000000000, & !  1
      0.0000000000000000, & !  2
      0.0000000000000000, & !  3
      0.0000000000000000, & !  4
      0.0000000000000000, & !  5
      0.0000000000000000, & !  6
      0.0000000000000000, & !  7
      0.0000000000000000, & !  8
      0.0000000000000000, & !  9
      0.0000000000000000, & ! 10
      0.0000000000000000, & ! 11
      0.0000000000000000, & ! 12
      0.0000000000000000, & ! 13
      0.0001055707738109, & ! 14
      0.0059372955912098, & ! 15
      0.0235354910761884, & ! 16
      0.0576432893794934, & ! 17
      0.1139595353789115, & ! 18
      0.1987640251563301, & ! 19
      0.3179517452840197, & ! 20
      0.4748134785123594, & ! 21
      0.6338019812807031, & ! 22
      0.7731855115963033, & ! 23
      0.8787837382816079, & ! 24
      0.9464020881646360, & ! 25
      0.9795195430185113, & ! 26
      1.0000000000000000  & ! 27
    ]

    p0 = 1d5 ! Pa

  end subroutine hybrid_coord_wrf_l26

  subroutine hybrid_coord_wrf_l32(p0, ptop, hyai, hybi)

    real(r8), intent(out) :: p0
    real(r8), intent(in ) :: ptop
    real(r8), intent(out) :: hyai(33)
    real(r8), intent(out) :: hybi(33)

    if (global_mesh%num_full_lev /= 32 .and. is_root_proc()) then
      call log_error('num_lev should be 32 in namelist!')
    end if

    hyai = [              &
      0.0000000000000000, & !  1
      0.0027008056640625, & !  2
      0.0076868347823620, & !  3
      0.0158526937798342, & !  4
      0.0276367470939261, & !  5
      0.0414515552099706, & !  6
      0.0562277844155789, & !  7
      0.0724737972365225, & !  8
      0.0893795253309864, & !  9
      0.1063548465048298, & ! 10
      0.1254725257849640, & ! 11
      0.1479642011314251, & ! 12
      0.1744233770857367, & ! 13
      0.2054476619883455, & ! 14
      0.2362396334209435, & ! 15
      0.2617261684535087, & ! 16
      0.2783057827853432, & ! 17
      0.2816243248017372, & ! 18
      0.2683280168286641, & ! 19
      0.2429473354807992, & ! 20
      0.2108099294331058, & ! 21
      0.1759998110016148, & ! 22
      0.1415334037742616, & ! 23
      0.1095123294032484, & ! 24
      0.0812761592574764, & ! 25
      0.0575423961814687, & ! 26
      0.0385285881906738, & ! 27
      0.0240694984015316, & ! 28
      0.0137226170696702, & ! 29
      0.0068720184783044, & ! 30
      0.0027973066609278, & ! 31
      0.0007580797514921, & ! 32
      0.0000000000000000  & ! 33
    ]
    hybi = [              &
      0.0000000000000000, & !  1
      0.0000000000000000, & !  2
      0.0000000000000000, & !  3
      0.0000000000000000, & !  4
      0.0000000000000000, & !  5
      0.0000000000000000, & !  6
      0.0000000000000000, & !  7
      0.0000000000000000, & !  8
      0.0000000000000000, & !  9
      0.0000000000000000, & ! 10
      0.0000000000000000, & ! 11
      0.0000000000000000, & ! 12
      0.0000000000000000, & ! 13
      0.0001056069805219, & ! 14
      0.0059397906834944, & ! 15
      0.0235374270991938, & ! 16
      0.0576439176162314, & ! 17
      0.1139578493851603, & ! 18
      0.1932313936022966, & ! 19
      0.2808764820852269, & ! 20
      0.3715629284436812, & ! 21
      0.4612091687348547, & ! 22
      0.5467954414732804, & ! 23
      0.6262219272258057, & ! 24
      0.6981497395977654, & ! 25
      0.7618575996945027, & ! 26
      0.8171268253424389, & ! 27
      0.8641240158900223, & ! 28
      0.9032994538662682, & ! 29
      0.9352560448161740, & ! 30
      0.9607227915792738, & ! 31
      0.9804356127137464, & ! 32
      1.0000000000000000  & ! 33
    ]

    p0 = 1d5       ! Pa

  end subroutine hybrid_coord_wrf_l32

  subroutine hybrid_coord_wrf_l60(p0, ptop, hyai, hybi)

    real(r8), intent(out) :: p0
    real(r8), intent(in ) :: ptop
    real(r8), intent(out) :: hyai(61)
    real(r8), intent(out) :: hybi(61)

    if (global_mesh%num_full_lev /= 60 .and. is_root_proc()) then
      call log_error('num_lev should be 60 in namelist!')
    end if

    hyai = [ &
      0.0000000000000000, 0.0166666666666667, 0.0333333333333333, &
      0.0500000000000000, 0.0666666666666667, 0.0833333333333333, &
      0.1000000000000000, 0.1166666666666667, 0.1333333333333333, &
      0.1500000000000000, 0.1666666666666667, 0.1833333333333333, &
      0.2000000000000000, 0.2157226562500000, 0.2296006944444444, &
      0.2416992187500000, 0.2520833333333333, 0.2608181423611111, &
      0.2679687500000000, 0.2736002604166666, 0.2777777777777778, &
      0.2805664062500000, 0.2820312500000000, 0.2822374131944445, &
      0.2812500000000000, 0.2791341145833334, 0.2759548611111111, &
      0.2717773437500000, 0.2666666666666667, 0.2606879340277780, &
      0.2539062500000000, 0.2463867187500000, 0.2381944444444444, &
      0.2293945312500000, 0.2200520833333336, 0.2102322048611110, &
      0.2000000000000000, 0.1894205729166667, 0.1785590277777778, &
      0.1674804687499999, 0.1562500000000000, 0.1449327256944448, &
      0.1335937500000000, 0.1222981770833331, 0.1111111111111114, &
      0.1000976562500000, 0.0893229166666668, 0.0788519965277780, &
      0.0687499999999999, 0.0590820312500000, 0.0499131944444443, &
      0.0413085937500000, 0.0333333333333337, 0.0260525173611112, &
      0.0195312500000000, 0.0138346354166669, 0.0090277777777781, &
      0.0051757812500000, 0.0023437500000000, 0.0005967881944450, &
      0.0000000000000000 &
    ]
    hybi = [ &
      0.0000000000000000, 0.0000000000000000, 0.0000000000000000, &
      0.0000000000000000, 0.0000000000000000, 0.0000000000000000, &
      0.0000000000000000, 0.0000000000000000, 0.0000000000000000, &
      0.0000000000000000, 0.0000000000000000, 0.0000000000000000, &
      0.0000000000000000, 0.0009440104166667, 0.0037326388888889, &
      0.0083007812500000, 0.0145833333333334, 0.0225151909722222, &
      0.0320312500000000, 0.0430664062500000, 0.0555555555555555, &
      0.0694335937499999, 0.0846354166666666, 0.1010959201388889, &
      0.1187500000000000, 0.1375325520833333, 0.1573784722222222, &
      0.1782226562499999, 0.2000000000000000, 0.2226453993055554, &
      0.2460937499999999, 0.2702799479166667, 0.2951388888888889, &
      0.3206054687499998, 0.3466145833333331, 0.3731011284722224, &
      0.4000000000000000, 0.4272460937500000, 0.4547743055555555, &
      0.4825195312500001, 0.5104166666666665, 0.5384006076388885, &
      0.5664062499999998, 0.5943684895833335, 0.6222222222222219, &
      0.6499023437500000, 0.6773437499999999, 0.7044813368055554, &
      0.7312500000000002, 0.7575846354166664, 0.7834201388888891, &
      0.8086914062499995, 0.8333333333333330, 0.8572808159722221, &
      0.8804687499999999, 0.9028320312499998, 0.9243055555555553, &
      0.9448242187499996, 0.9643229166666663, 0.9827365451388883, &
      1.0000000000000000 &
    ]

    p0 = 1d5       ! Pa

  end subroutine hybrid_coord_wrf_l60

  subroutine hybrid_coord_wrf_l64(p0, ptop, hyai, hybi)

    real(r8), intent(out) :: p0
    real(r8), intent(in ) :: ptop
    real(r8), intent(out) :: hyai(65)
    real(r8), intent(out) :: hybi(65)

    if (global_mesh%num_full_lev /= 64 .and. is_root_proc()) then
      call log_error('num_lev should be 64 in namelist!')
    end if

    hyai = [          &
      0.00000000e+00, & !  1
      1.56250000e-02, & !  2
      3.12500000e-02, & !  3
      4.68750000e-02, & !  4
      6.25000000e-02, & !  5
      7.81250000e-02, & !  6
      9.37500000e-02, & !  7
      1.09375000e-01, & !  8
      1.25000000e-01, & !  9
      1.40625000e-01, & !  10
      1.56250000e-01, & !  11
      1.71875000e-01, & !  12
      1.87500000e-01, & !  13
      2.03091502e-01, & !  14
      2.17556953e-01, & !  15
      2.30408311e-01, & !  16
      2.41699219e-01, & !  17
      2.51483321e-01, & !  18
      2.59814262e-01, & !  19
      2.66745687e-01, & !  20
      2.72331238e-01, & !  21
      2.76624560e-01, & !  22
      2.79679298e-01, & !  23
      2.81549096e-01, & !  24
      2.82287598e-01, & !  25
      2.81948447e-01, & !  26
      2.80585289e-01, & !  27
      2.78251767e-01, & !  28
      2.75001526e-01, & !  29
      2.70888209e-01, & !  30
      2.65965462e-01, & !  31
      2.60286927e-01, & !  32
      2.53906250e-01, & !  33
      2.46877074e-01, & !  34
      2.39253044e-01, & !  35
      2.31087804e-01, & !  36
      2.22434998e-01, & !  37
      2.13348269e-01, & !  38
      2.03881264e-01, & !  39
      1.94087625e-01, & !  40
      1.84020996e-01, & !  41
      1.73735023e-01, & !  42
      1.63283348e-01, & !  43
      1.52719617e-01, & !  44
      1.42097473e-01, & !  45
      1.31470561e-01, & !  46
      1.20892525e-01, & !  47
      1.10417008e-01, & !  48
      1.00097656e-01, & !  49
      8.99881124e-02, & !  50
      8.01420212e-02, & !  51
      7.06130266e-02, & !  52
      6.14547729e-02, & !  53
      5.27209044e-02, & !  54
      4.44650650e-02, & !  55
      3.67408991e-02, & !  56
      2.96020508e-02, & !  57
      2.31021643e-02, & !  58
      1.72948837e-02, & !  59
      1.22338533e-02, & !  60
      7.97271729e-03, & !  61
      4.56511974e-03, & !  62
      2.06470490e-03, & !  63
      5.25116920e-04, & !  64
      4.44089210e-16  & !  65
    ]
    hybi = [          &
      0.00000000e+00, & !  1
      0.00000000e+00, & !  2
      0.00000000e+00, & !  3
      0.00000000e+00, & !  4
      0.00000000e+00, & !  5
      0.00000000e+00, & !  6
      0.00000000e+00, & !  7
      0.00000000e+00, & !  8
      0.00000000e+00, & !  9
      0.00000000e+00, & !  10
      0.00000000e+00, & !  11
      0.00000000e+00, & !  12
      0.00000000e+00, & !  13
      3.34978104e-05, & !  14
      1.19304657e-03, & !  15
      3.96668911e-03, & !  16
      8.30078125e-03, & !  17
      1.41416788e-02, & !  18
      2.14357376e-02, & !  19
      3.01293135e-02, & !  20
      4.01687622e-02, & !  21
      5.15004396e-02, & !  22
      6.40707016e-02, & !  23
      7.78259039e-02, & !  24
      9.27124023e-02, & !  25
      1.08676553e-01, & !  26
      1.25664711e-01, & !  27
      1.43623233e-01, & !  28
      1.62498474e-01, & !  29
      1.82236791e-01, & !  30
      2.02784538e-01, & !  31
      2.24088073e-01, & !  32
      2.46093750e-01, & !  33
      2.68747926e-01, & !  34
      2.91996956e-01, & !  35
      3.15787196e-01, & !  36
      3.40065002e-01, & !  37
      3.64776731e-01, & !  38
      3.89868736e-01, & !  39
      4.15287375e-01, & !  40
      4.40979004e-01, & !  41
      4.66889977e-01, & !  42
      4.92966652e-01, & !  43
      5.19155383e-01, & !  44
      5.45402527e-01, & !  45
      5.71654439e-01, & !  46
      5.97857475e-01, & !  47
      6.23957992e-01, & !  48
      6.49902344e-01, & !  49
      6.75636888e-01, & !  50
      7.01107979e-01, & !  51
      7.26261973e-01, & !  52
      7.51045227e-01, & !  53
      7.75404096e-01, & !  54
      7.99284935e-01, & !  55
      8.22634101e-01, & !  56
      8.45397949e-01, & !  57
      8.67522836e-01, & !  58
      8.88955116e-01, & !  59
      9.09641147e-01, & !  60
      9.29527283e-01, & !  61
      9.48559880e-01, & !  62
      9.66685295e-01, & !  63
      9.83849883e-01, & !  64
      1.00000000e+00  & !  65
    ]

    p0 = 1d5       ! Pa

  end subroutine hybrid_coord_wrf_l64

  subroutine hybrid_coord_schar_l40(p0, ptop, hyai, hybi)

    real(r8), intent(out) :: p0
    real(r8), intent(out) :: ptop
    real(r8), intent(out) :: hyai(41)
    real(r8), intent(out) :: hybi(41)

    if (global_mesh%num_full_lev /= 40 .and. is_root_proc()) then
      call log_error('num_lev should be 40 in namelist!')
    end if

    hyai = [                  &
      0.1025039799580591_r8 , & !  1
      0.1085106112775176_r8 , & !  2
      0.1148692252207011_r8 , & !  3
      0.1216004476194305_r8 , & !  4
      0.1287261129587656_r8 , & !  5
      0.1362693352028837_r8 , & !  6
      0.1442545827712838_r8 , & !  7
      0.1527077579085218_r8 , & !  8
      0.1616562807049334_r8 , & !  9
      0.1711291780408878_r8 , & ! 10
      0.1811571777430863_r8 , & ! 11
      0.1917728082583264_r8 , & ! 12
      0.1904697560360646_r8 , & ! 13
      0.1992215664069182_r8 , & ! 14
      0.2081033503253796_r8 , & ! 15
      0.2170765373305924_r8 , & ! 16
      0.2260947251739_r8    , & ! 17
      0.2351025487717675_r8 , & ! 18
      0.2440344018023399_r8 , & ! 19
      0.2528129925300951_r8 , & ! 20
      0.2613477131840651_r8 , & ! 21
      0.2695327996814114_r8 , & ! 22
      0.2772452556464864_r8 , & ! 23
      0.2843425114885985_r8 , & ! 24
      0.2906597857277424_r8 , & ! 25
      0.2960071117496997_r8 , & ! 26
      0.3001659886776721_r8 , & ! 27
      0.302885610008119_r8  , & ! 28
      0.3038786180077924_r8 , & ! 29
      0.3028163255331611_r8 , & ! 30
      0.299323339829651_r8  , & ! 31
      0.2929715149035437_r8 , & ! 32
      0.2832731501298948_r8 , & ! 33
      0.2696733427488229_r8 , & ! 34
      0.2515413906792607_r8 , & ! 35
      0.2281611294972407_r8 , & ! 36
      0.1987200733208144_r8 , & ! 37
      0.1622972135317635_r8 , & ! 38
      0.1178493115391018_r8 , & ! 39
      0.06419550191988976_r8, & ! 40
      0.0_r8                  & ! 41
    ]
    hybi = [                  &
      0.0_r8                , & !  1
      0.0_r8                , & !  2
      0.0_r8                , & !  3
      0.0_r8                , & !  4
      0.0_r8                , & !  5
      0.0_r8                , & !  6
      0.0_r8                , & !  7
      0.0_r8                , & !  8
      0.0_r8                , & !  9
      0.0_r8                , & ! 10
      0.0_r8                , & ! 11
      0.0_r8                , & ! 12
      0.01254074813198438_r8, & ! 13
      0.01568515147901569_r8, & ! 14
      0.01939668757548295_r8, & ! 15
      0.02375477661820929_r8, & ! 16
      0.02884906434573413_r8, & ! 17
      0.03478069335699107_r8, & ! 18
      0.0416637300061256_r8 , & ! 19
      0.04962676577066524_r8, & ! 20
      0.05881471427746436_r8, & ! 21
      0.06939082773441382_r8, & ! 22
      0.08153895938918876_r8, & ! 23
      0.09546610185670711_r8, & ! 24
      0.111405234766373_r8  , & ! 25
      0.1296185192255581_r8 , & ! 26
      0.1504008811297395_r8 , & ! 27
      0.1740840304312517_r8 , & ! 28
      0.2010409691738044_r8 , & ! 29
      0.231691047482839_r8  , & ! 30
      0.2665056338554453_r8 , & ! 31
      0.3060144741109534_r8 , & ! 32
      0.3508128223486922_r8 , & ! 33
      0.4015694373296012_r8 , & ! 34
      0.4590355489842755_r8 , & ! 35
      0.5240549123983681_r8 , & ! 36
      0.5975750808014414_r8 , & ! 37
      0.6806600449716177_r8 , & ! 38
      0.7745044042722101_r8 , & ! 39
      0.8804492544892654_r8 , & ! 40
      1.0_r8                  & ! 41
    ]

    p0 = 1d5       ! Pa
    ptop = p0 * hyai(1)

  end subroutine hybrid_coord_schar_l40

  subroutine hybrid_coord_dcmip21_l60(p0, ptop, hyai, hybi)

    real(r8), intent(out) :: p0
    real(r8), intent(out) :: ptop
    real(r8), intent(out) :: hyai(61)
    real(r8), intent(out) :: hybi(61)

    if (global_mesh%num_full_lev /= 60 .and. is_root_proc()) then
      call log_error('num_lev should be 60 in namelist!')
    end if

    hyai = [                   &
      0.03281792304784018_r8 , & !  1
      0.03474102071194446_r8 , & !  2
      0.03677680998728482_r8 , & !  3
      0.03893189449024544_r8 , & !  4
      0.04121326480256544_r8 , & !  5
      0.04362832114712411_r8 , & !  6
      0.04618489739250437_r8 , & !  7
      0.04889128646419994_r8 , & !  8
      0.05175626724489389_r8 , & !  9
      0.0547891330510669_r8  , & ! 10
      0.05799972177830628_r8 , & ! 11
      0.06139844781310023_r8 , & ! 12
      0.06499633581463152_r8 , & ! 13
      0.06880505647615068_r8 , & ! 14
      0.07283696438193012_r8 , & ! 15
      0.07710513808259807_r8 , & ! 16
      0.08162342251884733_r8 , & ! 17
      0.08640647393113107_r8 , & ! 18
      0.09146980740102234_r8 , & ! 19
      0.09682984717844971_r8 , & ! 20
      0.1025039799580591_r8  , & ! 21
      0.1085106112775176_r8  , & ! 22
      0.1148692252207011_r8  , & ! 23
      0.1216004476194305_r8  , & ! 24
      0.1287261129587656_r8  , & ! 25
      0.1350456081805054_r8  , & ! 26
      0.1427250473547907_r8  , & ! 27
      0.1508030763969775_r8  , & ! 28
      0.1592924802031636_r8  , & ! 29
      0.1682047034916206_r8  , & ! 30
      0.1775493685725172_r8  , & ! 31
      0.1873336879076161_r8  , & ! 32
      0.1975617507483634_r8  , & ! 33
      0.2082336591917547_r8  , & ! 34
      0.219344484300267_r8   , & ! 35
      0.2308830073555085_r8  , & ! 36
      0.2428302046894931_r8  , & ! 37
      0.2551574266661043_r8  , & ! 38
      0.267824212035116_r8   , & ! 39
      0.2807756677752939_r8  , & ! 40
      0.2939393313530507_r8  , & ! 41
      0.3072214166589859_r8  , & ! 42
      0.3205023262836642_r8  , & ! 43
      0.3336312907070463_r8  , & ! 44
      0.346419968751406_r8   , & ! 45
      0.3586348125120132_r8  , & ! 46
      0.3699879630156528_r8  , & ! 47
      0.3801263989752005_r8  , & ! 48
      0.388619008916789_r8   , & ! 49
      0.3949411951212309_r8  , & ! 50
      0.3984565444238701_r8  , & ! 51
      0.398395013798003_r8   , & ! 52
      0.3938269752447859_r8  , & ! 53
      0.3836323417875858_r8  , & ! 54
      0.3664638507145668_r8  , & ! 55
      0.3407034073507749_r8  , & ! 56
      0.3044101874928628_r8  , & ! 57
      0.2552589531818032_r8  , & ! 58
      0.1904667475740021_r8  , & ! 59
      0.106705791818907_r8   , & ! 60
      0.0_r8                   & ! 61
    ]
    hybi = [                   &
      0.0_r8                 , & !  1
      0.0_r8                 , & !  2
      0.0_r8                 , & !  3
      0.0_r8                 , & !  4
      0.0_r8                 , & !  5
      0.0_r8                 , & !  6
      0.0_r8                 , & !  7
      0.0_r8                 , & !  8
      0.0_r8                 , & !  9
      0.0_r8                 , & ! 10
      0.0_r8                 , & ! 11
      0.0_r8                 , & ! 12
      0.0_r8                 , & ! 13
      0.0_r8                 , & ! 14
      0.0_r8                 , & ! 15
      0.0_r8                 , & ! 16
      0.0_r8                 , & ! 17
      0.0_r8                 , & ! 18
      0.0_r8                 , & ! 19
      0.0_r8                 , & ! 20
      0.0_r8                 , & ! 21
      0.0_r8                 , & ! 22
      0.0_r8                 , & ! 23
      0.0_r8                 , & ! 24
      0.0_r8                 , & ! 25
      0.001223727022378311_r8, & ! 26
      0.001529535416493121_r8, & ! 27
      0.001904681511544389_r8, & ! 28
      0.002363800501769887_r8, & ! 29
      0.002924474549267209_r8, & ! 30
      0.003607809170569179_r8, & ! 31
      0.004439120350710344_r8, & ! 32
      0.005448753419685578_r8, & ! 33
      0.006673058694179184_r8, & ! 34
      0.008155553600595522_r8, & ! 35
      0.00994830659329325_r8 , & ! 36
      0.01211358483014104_r8 , & ! 37
      0.0147258154626543_r8  , & ! 38
      0.01787391977334953_r8 , & ! 39
      0.0216640905254665_r8  , & ! 40
      0.02622309610847879_r8 , & ! 41
      0.03170221075683934_r8 , & ! 42
      0.03828188875201099_r8 , & ! 43
      0.04617732263825928_r8 , & ! 44
      0.05564505174270933_r8 , & ! 45
      0.06699081846324466_r8 , & ! 46
      0.08057890679175883_r8 , & ! 47
      0.09684324146417017_r8 , & ! 48
      0.1163005782648078_r8  , & ! 49
      0.1395661778947692_r8  , & ! 50
      0.1673724292612262_r8  , & ! 51
      0.200590975216494_r8   , & ! 52
      0.2402589972338011_r8  , & ! 53
      0.2876104382908383_r8  , & ! 54
      0.3441130889489694_r8  , & ! 55
      0.4115126345448339_r8  , & ! 56
      0.491884966629393_r8   , & ! 57
      0.587698305321578_r8   , & ! 58
      0.7018869682373099_r8  , & ! 59
      0.8379389645902481_r8  , & ! 60
      1.0_r8                   & ! 61
    ]

    p0 = 1d5 ! Pa
    ptop = p0 * hyai(1)

  end subroutine hybrid_coord_dcmip21_l60

  subroutine hybrid_coord_dcmip31_l10(p0, ptop, hyai, hybi)

    real(r8), intent(out) :: p0
    real(r8), intent(out) :: ptop
    real(r8), intent(out) :: hyai(11)
    real(r8), intent(out) :: hybi(11)

    if (global_mesh%num_full_lev /= 10 .and. is_root_proc()) then
      call log_error('num_lev should be 10 in namelist!')
    end if

    hyai = [                  &
      0.2737592327457158_r8 , & !  1
      0.2574691274856134_r8 , & !  2
      0.2392257778961169_r8 , & !  3
      0.2188579122253837_r8 , & !  4
      0.1961834482057335_r8 , & !  5
      0.171008960410953_r8  , & !  6
      0.1431291236866448_r8 , & !  7
      0.1123261317013542_r8 , & !  8
      0.07836908962461686_r8, & !  9
      0.04101337989532572_r8, & ! 10
      0.0_r8                  & ! 11
    ]
    hybi = [                  &
      0.0_r8                , & !  1
      0.05950522689853417_r8, & !  2
      0.1261453522616924_r8 , & !  3
      0.2005460052239693_r8 , & !  4
      0.283372304056826_r8  , & !  5
      0.3753308018298088_r8 , & !  6
      0.4771715194731282_r8 , & !  7
      0.5896900697201707_r8 , & !  8
      0.7137298755603581_r8 , & !  9
      0.8501844869888955_r8 , & ! 10
      1.0_r8                  & ! 11
    ]

    p0 = 1d5 ! Pa
    ptop = p0 * hyai(1)

  end subroutine hybrid_coord_dcmip31_l10

  subroutine hybrid_coord_waccm_l70(p0, ptop, hyai, hybi)

    real(r8), intent(out) :: p0
    real(r8), intent(out) :: ptop
    real(r8), intent(out) :: hyai(71)
    real(r8), intent(out) :: hybi(71)

    if (global_mesh%num_full_lev /= 70 .and. is_root_proc()) then
      call log_error('num_lev should be 70 in namelist!')
    end if

    hyai = [                &
      4.50049997269275e-09, &
      7.42010008991656e-09, &
      1.22337002750328e-08, &
      2.01700007806949e-08, &
      3.32545013748131e-08, &
      5.48274989853326e-08, &
      9.03979966437873e-08, &
      1.49040005226198e-07, &
      2.45720002567396e-07, &
      4.05125007318929e-07, &
      6.67940014409396e-07, &
      1.10126495656004e-06, &
      1.81564996637462e-06, &
      2.99349994747899e-06, &
      4.96299981023185e-06, &
      8.15065141068771e-06, &
      1.34769998112461e-05, &
      2.23189999815077e-05, &
      3.67965003533754e-05, &
      6.0664999182336e-05 , &
      9.91565029835328e-05, &
      0.000157389993546531, &
      0.000238849999732338, &
      0.00034520000917837 , &
      0.000475134991575032, &
      0.000631804985459894, &
      0.000829154974780977, &
      0.00108274002559483 , &
      0.00140684994403273 , &
      0.00181885005440563 , &
      0.00233979988843203 , &
      0.00299505004659295 , &
      0.00381470005959272 , &
      0.00483444985002279 , &
      0.00609635002911091 , &
      0.00764934998005629 , &
      0.00955010019242764 , &
      0.0118640000000596  , &
      0.0146655002608895  , &
      0.0180380009114742  , &
      0.0220755003392696  , &
      0.0268824994564056  , &
      0.0325734987854958  , &
      0.0392730012536049  , &
      0.0471144989132881  , &
      0.0562404990196228  , &
      0.0668004974722862  , &
      0.0807014182209969  , &
      0.0949410423636436  , &
      0.11169321089983    , &
      0.131401270627975   , &
      0.154586806893349   , &
      0.181863352656364   , &
      0.17459799349308    , &
      0.166050657629967   , &
      0.155995160341263   , &
      0.14416541159153    , &
      0.130248308181763   , &
      0.113875567913055   , &
      0.0946138575673103  , &
      0.0753444507718086  , &
      0.0576589405536652  , &
      0.0427346378564835  , &
      0.0316426791250706  , &
      0.0252212174236774  , &
      0.0191967375576496  , &
      0.0136180268600583  , &
      0.00853108894079924 , &
      0.00397881818935275 , &
      0.00000000000000000 , &
      0.00000000000000000   &
    ]
    hybi = [                &
      0.000000000000000000, &
      0.000000000000000000, &
      0.000000000000000000, &
      0.000000000000000000, &
      0.000000000000000000, &
      0.000000000000000000, &
      0.000000000000000000, &
      0.000000000000000000, &
      0.000000000000000000, &
      0.000000000000000000, &
      0.000000000000000000, &
      0.000000000000000000, &
      0.000000000000000000, &
      0.000000000000000000, &
      0.000000000000000000, &
      0.000000000000000000, &
      0.000000000000000000, &
      0.000000000000000000, &
      0.000000000000000000, &
      0.000000000000000000, &
      0.000000000000000000, &
      0.000000000000000000, &
      0.000000000000000000, &
      0.000000000000000000, &
      0.000000000000000000, &
      0.000000000000000000, &
      0.000000000000000000, &
      0.000000000000000000, &
      0.000000000000000000, &
      0.000000000000000000, &
      0.000000000000000000, &
      0.000000000000000000, &
      0.000000000000000000, &
      0.000000000000000000, &
      0.000000000000000000, &
      0.000000000000000000, &
      0.000000000000000000, &
      0.000000000000000000, &
      0.000000000000000000, &
      0.000000000000000000, &
      0.000000000000000000, &
      0.000000000000000000, &
      0.000000000000000000, &
      0.000000000000000000, &
      0.000000000000000000, &
      0.000000000000000000, &
      0.000000000000000000, &
      0.000000000000000000, &
      0.000000000000000000, &
      0.000000000000000000, &
      0.000000000000000000, &
      0.000000000000000000, &
      0.000000000000000000, &
      0.0393548272550106  , & 
      0.0856537595391273  , &
      0.140122056007385   , &
      0.204201176762581   , &
      0.279586911201477   , &
      0.368274360895157   , &
      0.47261056303978    , &
      0.576988518238068   , &
      0.672786951065063   , &
      0.753628432750702   , &
      0.813710987567902   , &
      0.848494648933411   , &
      0.881127893924713   , &
      0.911346435546875   , &
      0.938901245594025   , &
      0.963559806346893   , &
      0.985112190246582   , &
      1.000000000000000     &
    ]

    p0 = 1d5 ! Pa
    ptop = p0 * hyai(1)

  end subroutine hybrid_coord_waccm_l70

end module hybrid_coord_test_mod
